class PubSub {
	constructor() {
		this.subers = [];
	}

	sub(topic, callback) {
		let callbacks = this.subers[topic];
		if (!callbacks) {
			this.subers[topic] = [callback];
		} else {
			callbacks.push(callback);
		}
	}

	pub(topic, ...args) {
		let callbacks = this.subers[topic];
		callbacks.forEach(callback => callback(...args))
	}
}

const aEvent = (msg) => {
	console.log(msg + 'aaa');
}

const bEvent = (msg) => {
	console.log(msg + 'bbb');
}

let pubsub = new PubSub();

pubsub.sub('a', aEvent)
pubsub.sub('b', bEvent)

pubsub.pub('a', 'A订阅者')
pubsub.pub('b', 'B订阅者')

